package io;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class ObjectStreamTest {
    public static void main(String[] args) {
        ObjectOutput objectOutput = null;
        OutputStream outputStream=null;
        InputStream inputStream=null;
        ObjectInputStream objectInputStream=null;
        BufferedOutputStream bufferedOutputStream=null;
        try {
            outputStream=new FileOutputStream("d:/3.txt");
            objectOutput = new ObjectOutputStream(outputStream);
           bufferedOutputStream = new BufferedOutputStream(outputStream);
            List<Student> students = new ArrayList<>();
            Student stu1 = new Student(1, "李华");
            Student stu2 = new Student(3, "李华2");
            Student stu3 = new Student(3, "李华1");
            students.add(stu1);
            students.add(stu2);
            students.add(stu3);
            objectOutput.writeObject(students);
            Object student =null;
            inputStream = new FileInputStream("d:/3.txt");

            objectInputStream = new ObjectInputStream(inputStream);
            List<Student> o =(List<Student>) objectInputStream.readObject();
                System.out.println(o);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            try {
                objectInputStream.close();
                objectOutput.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
